<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>XMLHttpRequest Demo</title>
</head>
<body>
<p>打开控制台查看输出。</p>

<script>
  var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") // 兼容 IE6

  xhr.responseType = 'json'
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
      if (xhr.status >= 200 && xhr.status <= 300) {
        console.log(xhr.response)
      } else {
        console.error(xhr)
      }
    }
  }

  // 打开请求：请求方式（GET），请求地址，是否异步
  xhr.open('GET', '/data.json', true)
  // 发送请求
  xhr.send(null)
</script>
</body>
</html>
